package com.sweet.fourtimeoa.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sweet.fourtimeoa.mapper.DocumentMapper;
import com.sweet.fourtimeoa.pojo.dto.DocumentList;
import com.sweet.fourtimeoa.pojo.dto.DocumentQueryDto;
import com.sweet.fourtimeoa.pojo.dto.PageDto;
import com.sweet.fourtimeoa.pojo.entity.Documents;
import com.sweet.fourtimeoa.pojo.vo.PageVo;
import com.sweet.fourtimeoa.service.DocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DocumentServiceImpl implements DocumentService {

    @Autowired
    private DocumentMapper documentMapper;

    @Override
    public PageVo<DocumentList> getDocumentList(PageDto<DocumentQueryDto> pageDto) {
        PageHelper.startPage(pageDto.getPageNum(), pageDto.getPageSize());
        Page<DocumentList> list =(Page<DocumentList>)documentMapper.getDocumentList(pageDto.getData());
        PageVo<DocumentList> pageVo = new PageVo<>();
        pageVo.setPageNum(list.getPageNum());
        pageVo.setPageSize(list.getPageSize());
        pageVo.setTotal(list.getTotal());
        pageVo.setPages(list.getPages());
        pageVo.setList(list.getResult());
        return pageVo;
    }

    @Override
    public PageVo<DocumentList> getDocumentRecycleBin(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<DocumentList> list =(Page<DocumentList>)documentMapper.getDocumentRecycleBin();
        PageVo<DocumentList> pageVo = new PageVo<>();
        pageVo.setPageNum(list.getPageNum());
        pageVo.setPageSize(list.getPageSize());
        pageVo.setTotal(list.getTotal());
        pageVo.setPages(list.getPages());
        pageVo.setList(list.getResult());
        return pageVo;
    }

    @Override
    public boolean deleteDocument(Integer documentId) {
        return documentMapper.deleteDocument(documentId);
    }

    @Override
    public boolean updateDocumentRecycleBin(Integer documentId) {
        return documentMapper.updateDocumentRecycleBin(documentId);
    }

    @Override
    public boolean deleteDocumentRecycleBin(Integer documentId) {
        return documentMapper.deleteDocumentRecycleBin(documentId);
    }

    @Override
    public void saveDocument(Documents documents) {
        documentMapper.saveDocument(documents);
    }

}
